/**
 * @param {number[]} nums
 * @param {number[]} quantity
 * @return {boolean}
 */
 var canDistribute = function(nums, quantity) {
     let type = true
     let numsArr = [...new Set(nums)]
     let newArr = []
     numsArr.forEach(item=>{
         let dataArr = nums.filter(num => item == num)
         newArr.push(dataArr.length)
     })
    newArr.sort((a,b)=>b-a)
    quantity.sort((a,b)=> b-a)
    console.log(newArr,quantity)
    for(let i=0; i<newArr.length; i++){
        type = false
        function fn(){
            let quantityArr = subsets(quantity)
            let quantityDataArr = quantityArr.map(item2=>{
                let i = {
                    add:0,
                    index:[]
                }
                item2.forEach((item3,index)=>(i.add = i.add + item3,i.index.push(index)))
                return i
            })
            quantityDataArr.forEach(item2=>{
                if(newArr[i] == item2.add){
                    item2.index.forEach(index=>quantity.splice(index,1))
                    newArr.splice(i,1)
                    type = true
                    fn()
                }
            })
        }
        fn()
    }
    return type
};
var subsets = function(nums) {
    let res = [], len = nums.length;
    for (let i = 0; i < (1 << len); i++) {
		let arr = [];
        for (let j = 0; j < len; j++) {
            if (i & (1 << j)) arr.push(nums[j]);
        }
        res.push(arr);
    }
    return res;
};
console.log(canDistribute([1,2,3,3],[2]))